home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / dev / lang / SmallEiffel.lha / SmallEiffel / lib_std / arrayed_collection.e < prev    next >
Text File  |  1998-12-22  |  3KB  |  113 lines

  1. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  2. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  3. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  4. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  5. -- this header is kept unaltered, and a notification of the changes is added.
  6. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  7. -- another product.
  8. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  9. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  10. --                       http://www.loria.fr/SmallEiffel
  11. --
  12. deferred class ARRAYED_COLLECTION[E]
  13.    -- 
  14.    -- Common root for ARRAY[E] and FIXED_ARRAY[E].
  15.    --
  16.  
  17. inherit COLLECTION[E];
  18.  
  19. feature {ARRAYED_COLLECTION}
  20.    
  21.    storage: NATIVE_ARRAY[E];
  22.      -- Internal access to storage location.
  23.    
  24. feature
  25.    
  26.    capacity: INTEGER;
  27.      -- Internal storage capacity in number of item.
  28.    
  29.    upper: INTEGER;
  30.      -- Upper index bound.
  31.    
  32. feature -- 
  33.  
  34.    sub_array(low, up: INTEGER): like Current is
  35.       require
  36.      valid_index(low);
  37.      valid_index(up);
  38.      low <= up
  39.       deferred
  40.       ensure
  41.      same_type(Result);
  42.      Result.count = (up - low + 1);
  43.      Result.lower = low or Result.lower = 0
  44.       end;
  45.  
  46. feature -- Implementation of deferred :
  47.  
  48.    add(element: like item; index: INTEGER) is
  49.       do
  50.      if index = upper + 1 then
  51.         add_last(element);
  52.      else
  53.         add_last(element);
  54.         move(index,upper - 1,1);
  55.         put(element,index);
  56.      end;
  57.       end;
  58.  
  59.    remove_last is
  60.       do
  61.      upper := upper - 1;
  62.       end;
  63.    
  64.    replace_all(old_value, new_value: like item) is
  65.       do
  66.      storage.replace_all(old_value,new_value,count - 1);
  67.       end;
  68.    
  69.    fast_replace_all(old_value, new_value: like item) is
  70.       do
  71.      storage.fast_replace_all(old_value,new_value,count - 1);
  72.       end;
  73.  
  74. feature -- The Guru section :
  75.  
  76.    frozen free is
  77.       obsolete "Replaced by automatic Garbage Collection. %
  78.              %Will be removed in the next release."
  79.       do
  80.       end;
  81.    
  82. feature -- Interfacing with C :
  83.    
  84.    to_external: POINTER is
  85.      -- Gives C access into the internal `storage' of the ARRAY.
  86.      -- Result is pointing the element at index `lower'.
  87.      -- 
  88.      -- NOTE: do not free/realloc the Result. Resizing of the array 
  89.      --       can makes this pointer invalid. 
  90.       require
  91.      not empty
  92.       do
  93.      Result := storage.to_pointer;
  94.       ensure
  95.      Result.is_not_void
  96.       end;
  97.  
  98. feature {ARRAYED_COLLECTION}
  99.  
  100.    set_upper(new_upper: like upper) is
  101.       do
  102.      upper := new_upper;
  103.       end;
  104.  
  105. invariant
  106.  
  107.    capacity >= (upper - lower + 1);
  108.  
  109.    capacity > 0 implies storage.is_not_void;
  110.  
  111. end -- ARRAYED_COLLECTION[E]
  112.  
  113.